package com.yspa.activityNotice.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.hsnn.medstgmini.dao.HibernateSqlUtil;
import com.hsnn.medstgmini.util.Pagination;
import com.yspa.activityNotice.dao.ActivityNoticeDao;
import com.yspa.activityNotice.model.form.ActivityNoticeForm;
@Repository
public class ActivityNoticeDaoImpl implements ActivityNoticeDao {

	@Autowired
	private HibernateSqlUtil dao;
	public Pagination getActivityNoticeList(Pagination page){
		StringBuffer sql = new StringBuffer();
		sql.append("select * from activity_notice")
		.append(" where 1=1 ");
		Map<String, Object> params = new HashMap<String, Object>();
		if (StringUtils.isNotBlank(page.getConditions().get("title"))){
			sql.append(" and title like :title");
			params.put("title", "%" + page.getConditions().get("title").trim() + "%");
		}
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	public void addActivityNotice(ActivityNoticeForm form){
		StringBuffer sql = new StringBuffer();
		sql.append("insert into activity_notice(id,title,content,img,create_time,is_top,status)")
		.append(" value(:id,:title,:content,:img,sysdate(),:isTop,:status)");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("id", UUID.randomUUID().toString());
		params.put("title", form.getTitle());
		params.put("content", form.getContent());
		params.put("img", form.getImgPath());
		params.put("isTop", form.getIsTop());
		params.put("status", 1);
		dao.executeSql(sql.toString(), params);
	}
	public List getEditInfo(String id){
		String sql = "select * from activity_notice where id=:id";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("id", id);
		return dao.getSqlMapList(sql, params);
	}
	public void editInfo(ActivityNoticeForm form){
		StringBuffer sql = new StringBuffer();
		sql.append("update activity_notice")
		.append(" set title=:title,")
		.append("content=:content,")
		.append("img=:img,")
		.append("is_top=:isTop")
		.append(" where id=:id");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("id", form.getId());
		params.put("title", form.getTitle());
		params.put("content", form.getContent());
		params.put("img", form.getImgPath());
		params.put("isTop", form.getIsTop());
		dao.executeSql(sql.toString(), params);
	}
	public void deleteUser(List<String> list){
		String sql = "delete from activity_notice where id in (:ids)";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("ids", list);
		dao.executeSql(sql, params);
	}

}
